package com.zk.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;


public class DBConnection {

	 private static String url;    
     private static String user;    
     private static String password;    
     public static Connection conn;    
     public static PreparedStatement ps;    
     public static ResultSet rs;    
     public static Statement st ;
     static{

     }
     public void getConnection(){  
    	 InputStream in = DBConnection.class.getClassLoader()
                 .getResourceAsStream("db.properties");
    	 Properties props = new Properties();
    	 try {
			props.load(in);
			url = props.getProperty("url");
			user = props.getProperty("user");
			password = props.getProperty("password");
            Class.forName("oracle.jdbc.driver.OracleDriver");    
            conn=DriverManager.getConnection(url, user, password);    
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
     } 
   //测试能否与oracle数据库连接成功     
     public static void main(String[] args) {    
    	 DBConnection basedao=new DBConnection(); 
    	 
        basedao.getConnection();    
        if(conn==null){    
            System.out.println("与oracle数据库连接失败！");    
        }else{    
            System.out.println("与oracle数据库连接成功！");    
        }  
     }
}
